<template>
  <el-cascader
    :value="orgId"
    :options="treeData"
    :props="props"
    clearable
    filterable
    :disabled="disabled"
    @change="changeOrg"
  ></el-cascader>
</template>

<script>
import organizationApi from '@/api/system/organizationApi'

export default {
  name: 'Organization',
  props: {
    disabled: {
      type: Boolean,
      default: false
    },
    value: {
      type: Number,
      default: null
    }
  },
  data() {
    return {
      treeData: [],
      props: { checkStrictly: true, emitPath: false, label: 'orgName', value: 'id' }
    }
  },
  computed: {
    orgId() {
      return this.value
    }
  },
  created() {
    this.getTree()
  },
  methods: {
    getTree() {
      organizationApi.getTree({}).then(res => {
        this.treeData = res.data
      })
    },
    changeOrg(value) {
      this.$emit('input', value)
    }
  }
}
</script>

<style scoped>

</style>
